import Vue from 'vue'
import VueRouter, { RouteConfig } from 'vue-router'
import Home from '../views/Home.vue'
import BaseLayout from "@/layout/BaseLayout.vue";
import DivBarLayout from "@/layout/DivBarLayout.vue";

Vue.use(VueRouter)

const routes: Array<RouteConfig> = [
  {
    path: '/',
    component: DivBarLayout,
    children:[
      {
        name:'Home',
        path:'',
        component:Home,
        meta:{
          title:'商品主页'
        }
      }
    ]
  },
  {
    path: '/notice',
    component: DivBarLayout,
    children:[
      {
        name:'Notice',
        path:'',
        component:() => import(/* webpackChunkName: "about" */ '../views/Notice.vue'),
        meta:{
          title:'通知公告'
        }
      }
    ]
  },
  {
    path: '/user',
    redirect:'service/info',
    component: DivBarLayout,
    children:[
      {
        name:'FeedBack',
        path:'order/feedback',
        component:() => import(/* webpackChunkName: "about" */ '../views/user/order/FeedBack.vue'),
        meta:{
          title:'投诉反馈'
        }
      },
      {
        name:'History',
        path:'order/history',
        component:() => import(/* webpackChunkName: "about" */ '../views/user/order/History.vue'),
        meta:{
          title:'历史订单'
        }
      },
      {
        name:'Info',
        path:'service/info',
        component:() => import(/* webpackChunkName: "about" */ '../views/user/service/Info.vue'),
        meta:{
          title:'我的资料'
        }
      },
      {
        name:'Wallet',
        path:'service/wallet',
        component:() => import(/* webpackChunkName: "about" */ '../views/user/service/Wallet.vue'),
        meta:{
          title:'我的钱包'
        }
      },
      {
        name:'Login',
        path:'status/login',
        component:() => import(/* webpackChunkName: "about" */ '../views/user/status/Login.vue'),
        meta:{
          title:'用户登录'
        }
      },
      {
        name:'Exit',
        path:'status/exit',
        component:() => import(/* webpackChunkName: "about" */ '../views/user/status/Exit.vue'),
        meta:{
          title:'用户退出'
        }
      }
    ]
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  document.title = to.meta.title + ' - 51酷玩'
  next()
})

export default router
